
package testemodulorede;

import java.io.*;
import java.net.*;

public class ClientHandler implements Runnable {

    private BufferedReader reader;
    private Socket sock;
    private ServerModule server;
    
    public ClientHandler( Socket _sock, ServerModule _server ){
        
        server = _server;
        try{
            
            sock = _sock;
            InputStreamReader streamReader = new InputStreamReader( sock.getInputStream() );
            reader = new BufferedReader( streamReader );
            
        }
        catch( Exception ex ){
            
            ex.printStackTrace();
            
        }

    }

    public synchronized void tellServer( String _message ){

        server.incommingGameData(_message);

    }

    public void run(){
        
        String message;
        
        try{
        
            while( (message = reader.readLine()) != null ){
                
               System.out.println( "read " + message );

               tellServer( message );
            }
        }

        catch( Exception ex ){
            
            ex.printStackTrace();
            
        }

    }

}
